package com.pvdnc.tapkit.chat.ui.friend;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.PopupWindow;

import com.pvdnc.nsocket.log.SLog;
import com.pvdnc.tapkit.chat.ManagedReference;
import com.pvdnc.tapkit.chat.R;

public class SessionPopup {
    private static final SLog LOG=new SLog(SessionPopup.class);

    private Activity mActivity;

    public SessionPopup(Activity activity) {
        mActivity=activity;
    }

    private final ManagedReference<Intent> mIntent=new ManagedReference<>();

    private String mPositiveText;
    private View.OnClickListener mOnPositiveClick;
    public void setPositiveText(String positiveText) {
        this.mPositiveText = positiveText;
    }

    public void setOnPositiveClick(View.OnClickListener onPositiveClick) {
        this.mOnPositiveClick = onPositiveClick;
    }

    private String mNegativeText;
    private View.OnClickListener mOnNegativeClick;

    public void setNegativeText(String negativeText) {
        this.mNegativeText = negativeText;
    }

    public void setOnNegativeClick(View.OnClickListener onNegativeClick) {
        this.mOnNegativeClick = onNegativeClick;
    }

    public void show(final View parent){
        LinearLayout lyPopup=new LinearLayout(mActivity);
        lyPopup.setOrientation(LinearLayout.HORIZONTAL);

        final PopupWindow popupWindow=new PopupWindow(lyPopup,
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //正向按钮
        Button cmdPositive=new Button(mActivity);
        cmdPositive.setText(mPositiveText);
        cmdPositive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnPositiveClick.onClick(v);
                popupWindow.dismiss();
            }
        });
        lyPopup.addView(cmdPositive);
        //负向按钮
        Button cmdNegative=new Button(mActivity);
        cmdNegative.setText(mNegativeText);
        cmdNegative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mOnNegativeClick.onClick(v);
                popupWindow.dismiss();
            }
        });
        lyPopup.addView(cmdNegative);
        LOG.d("attempt to show session popup window");
        popupWindow.setOutsideTouchable(false);
        popupWindow.showAsDropDown(parent);
    }
}
